package com.itheima.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.health.entity.PageResult;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.mapper.CheckItemMapper;
import com.itheima.health.pojo.CheckItem;
import com.itheima.health.service.CheckItemService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class CheckItemServiceImpl extends ServiceImpl<CheckItemMapper, CheckItem> implements CheckItemService {
    public  static final Logger logger = LoggerFactory.getLogger(CheckItemServiceImpl.class);
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        logger.info("---------日志========");
        Page pageData =null;
        //  条件构造器
        QueryWrapper<CheckItem> wrapper = new QueryWrapper<CheckItem>();
        wrapper.eq("is_delete",0);
        //  1  mp  分页查询   完成分页查询   select  *  from   xxx  limit     count(1)
        if(StringUtils.isBlank(queryPageBean.getQueryString())){
            //  无条件分页
            //  page  结合 分页插件
            pageData   = page(new Page(queryPageBean.getCurrentPage(), queryPageBean.getPageSize()),wrapper);
        }else{
            wrapper.like("name",queryPageBean.getQueryString()); //  and 条件
            pageData   = page(new Page(queryPageBean.getCurrentPage(), queryPageBean.getPageSize()),wrapper);
        }
        // 2  结果集封装 PageResult返回
        PageResult pageResult = new PageResult(pageData.getTotal(),pageData.getRecords());
        return pageResult;
    }

    //恢复删除选项
    @Override
    public PageResult findalldelete(QueryPageBean pageBean) {
        QueryWrapper<CheckItem> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete",1);
        Page<CheckItem> page = page(new Page(pageBean.getCurrentPage(), pageBean.getPageSize()),queryWrapper);
        PageResult  result = new PageResult(page.getTotal(),page.getRecords());
        return result;
    }

}
